* This Do-File estimates the means and confidence intervals of the carbon footprint of the 2020 ECPR General Conference.
* Assuming that it had taken place in a hybrid format with 10%, 25%, or 50% of the participants randomly chosen to join virtually, 
* while the others take part in person.

******************************************************
**			50% online, randomly chosen 			**
******************************************************

clear all
cd "YOUR_PATH"



import excel "SimulationHybrid.xlsx", sheet("Tabelle1") firstrow

expand(anzahl_presenter)

keep if Year ==2020

*generate ID 
gen ID = _n

gen  uk_5bus = UK_5hBUS / anzahl_presenter
gen  uk_5train = UK_5hTRAIN / anzahl_presenter
gen  uba_5bus = UBA_5hBUS / anzahl_presenter
gen  uba_5train = UBA_5hTRAIN / anzahl_presenter
gen  eea_5bus = EEA_5hBUS / anzahl_presenter
gen  eea_5train = EEA_5hTRAIN / anzahl_presenter
gen  ntm_5bus = NTM_RFI2__5hBUS / anzahl_presenter
gen  ntm_5train = NTM_RFI2__5hTRAIN / anzahl_presenter
gen  ntm_5train_green = NTM_RFI2__5hTRAIN_Green_energy / anzahl_presenter

gen  uk_20bus = UK_20hBUS / anzahl_presenter
gen  uk_20train = UK_20hTRAIN / anzahl_presenter
gen  uba_20bus = UBA_20h_BUS / anzahl_presenter
gen  uba_20train = UBA_20hTRAIN / anzahl_presenter
gen  eea_20bus = EEA_20hBUS / anzahl_presenter
gen  eea_20train = EEA_20hTRAIN / anzahl_presenter
gen  ntm_20bus = NTM_RFI2__20hBUS / anzahl_presenter
gen  ntm_20train = NTM_RFI2__20hTRAIN / anzahl_presenter
gen  ntm_20train_green = NTM_RFI2__20hTRAIN_Green_energy / anzahl_presenter

sort uk_5bus
sort uk_5train
sort uba_5bus
sort uba_5train
sort eea_5bus
sort eea_5train
sort ntm_5bus
sort ntm_5train
sort ntm_5train_green

sort uk_20bus
sort uk_20train
sort uba_20bus
sort uba_20train
sort eea_20bus
sort eea_20train
sort ntm_20bus
sort ntm_20train
sort ntm_20train_green


*Draw 2500 random samples of 1104 participants (50% of all participants)
forvalues i= 1/2500 {
generate random = runiform()
sort random
gen sample_`i' = _n <= 1104
drop random
} 


* Averages for each sample
gen uk_5bus_mean = .
forvalues i=1/2500{
sum uk_5bus if sample_`i' ==1
replace uk_5bus_mean = r(mean) if ID == `i'
}

gen uk_5train_mean = .
forvalues i=1/2500{
sum uk_5train if sample_`i' ==1
replace uk_5train_mean = r(mean) if ID == `i'
}

gen uk_20bus_mean = .
forvalues i=1/2500{
sum uk_20bus if sample_`i' ==1
replace uk_20bus_mean = r(mean) if ID == `i'
}

gen uk_20train_mean = .
forvalues i=1/2500{
sum uk_20train if sample_`i' ==1
replace uk_20train_mean = r(mean) if ID == `i'
}


gen uba_5bus_mean = .
forvalues i=1/2500{
sum uba_5bus if sample_`i' ==1
replace uba_5bus_mean = r(mean) if ID == `i'
}

gen uba_5train_mean = .
forvalues i=1/2500{
sum uba_5train if sample_`i' ==1
replace uba_5train_mean = r(mean) if ID == `i'
}

gen uba_20bus_mean = .
forvalues i=1/2500{
sum uba_20bus if sample_`i' ==1
replace uba_20bus_mean = r(mean) if ID == `i'
}

gen uba_20train_mean = .
forvalues i=1/2500{
sum uba_20train if sample_`i' ==1
replace uba_20train_mean = r(mean) if ID == `i'
}


gen eea_5bus_mean = .
forvalues i=1/2500{
sum eea_5bus if sample_`i' ==1
replace eea_5bus_mean = r(mean) if ID == `i'
}

gen eea_5train_mean = .
forvalues i=1/2500{
sum eea_5train if sample_`i' ==1
replace eea_5train_mean = r(mean) if ID == `i'
}

gen eea_20bus_mean = .
forvalues i=1/2500{
sum eea_20bus if sample_`i' ==1
replace eea_20bus_mean = r(mean) if ID == `i'
}

gen eea_20train_mean = .
forvalues i=1/2500{
sum eea_20train if sample_`i' ==1
replace eea_20train_mean = r(mean) if ID == `i'
}


gen ntm_5bus_mean = .
forvalues i=1/2500{
sum ntm_5bus if sample_`i' ==1
replace ntm_5bus_mean = r(mean) if ID == `i'
}

gen ntm_5train_mean = .
forvalues i=1/2500{
sum ntm_5train if sample_`i' ==1
replace ntm_5train_mean = r(mean) if ID == `i'
}

gen ntm_5train_green_mean = .
forvalues i=1/2500{
sum ntm_5train_green if sample_`i' ==1
replace ntm_5train_green_mean = r(mean) if ID == `i'
}

gen ntm_20bus_mean = .
forvalues i=1/2500{
sum ntm_20bus if sample_`i' ==1
replace ntm_20bus_mean = r(mean) if ID == `i'
}

gen ntm_20train_mean = .
forvalues i=1/2500{
sum ntm_20train if sample_`i' ==1
replace ntm_20train_mean = r(mean) if ID == `i'
}

gen ntm_20train_green_mean = .
forvalues i=1/2500{
sum ntm_20train_green if sample_`i' ==1
replace ntm_20train_green_mean = r(mean) if ID == `i'
}

sort ID

* Variable 
input str50 estimation
"uk_5bus"
"uk_5train"
"uk_20bus"
"uk_20train"
"uba_5bus"
"uba_5train"
"uba_20bus"
"uba_20train"
"eea_5bus"
"eea_5train"
"eea_20bus"
"eea_20train"
"ntm_5bus"
"ntm_5train"
"ntm_5train_green"
"ntm_20bus"
"ntm_20train"
"ntm_20train_green"
end

* Generate table with means and sd of the averages
gen online50_mittelwert = .
gen online50_std = .

sum uk_5bus_mean
replace online50_mittelwert = r(mean) if ID == 1
replace online50_std = r(sd) if ID == 1

sum uk_5train_mean
replace online50_mittelwert = r(mean) if ID == 2
replace online50_std = r(sd) if ID == 2

sum uk_20bus_mean
replace online50_mittelwert = r(mean) if ID == 3
replace online50_std = r(sd) if ID == 3

sum uk_20train_mean
replace online50_mittelwert = r(mean) if ID == 4
replace online50_std = r(sd) if ID == 4

sum uba_5bus_mean
replace online50_mittelwert = r(mean) if ID == 5
replace online50_std = r(sd) if ID == 5

sum uba_5train_mean
replace online50_mittelwert = r(mean) if ID == 6
replace online50_std = r(sd) if ID == 6

sum uba_20bus_mean
replace online50_mittelwert = r(mean) if ID == 7
replace online50_std = r(sd) if ID == 7

sum uba_20train_mean
replace online50_mittelwert = r(mean) if ID == 8
replace online50_std = r(sd) if ID == 8

sum eea_5bus_mean
replace online50_mittelwert = r(mean) if ID == 9
replace online50_std = r(sd) if ID == 9

sum eea_5train_mean
replace online50_mittelwert = r(mean) if ID == 10
replace online50_std = r(sd) if ID == 10

sum eea_20bus_mean
replace online50_mittelwert = r(mean) if ID == 11
replace online50_std = r(sd) if ID == 11

sum eea_20train_mean
replace online50_mittelwert = r(mean) if ID == 12
replace online50_std = r(sd) if ID == 12

sum ntm_5bus_mean
replace online50_mittelwert = r(mean) if ID == 13
replace online50_std = r(sd) if ID == 13

sum ntm_5train_mean
replace online50_mittelwert = r(mean) if ID == 14
replace online50_std = r(sd) if ID == 14

sum ntm_5train_green_mean
replace online50_mittelwert = r(mean) if ID == 15
replace online50_std = r(sd) if ID == 15

sum ntm_20bus_mean
replace online50_mittelwert = r(mean) if ID == 16
replace online50_std = r(sd) if ID == 16

sum ntm_20train_mean
replace online50_mittelwert = r(mean) if ID == 17
replace online50_std = r(sd) if ID == 17

sum ntm_20train_green_mean
replace online50_mittelwert = r(mean) if ID == 18
replace online50_std = r(sd) if ID == 18

keep estimation online50_*
save "online50.dta", replace


******************************************************
**			25% online, randomly chosen 			**
******************************************************

clear all
import excel "SimulationHybrid.xlsx", sheet("Tabelle1") firstrow

expand(anzahl_presenter)

keep if Year ==2020

*generate ID
gen ID = _n

gen  uk_5bus = UK_5hBUS / anzahl_presenter
gen  uk_5train = UK_5hTRAIN / anzahl_presenter
gen  uba_5bus = UBA_5hBUS / anzahl_presenter
gen  uba_5train = UBA_5hTRAIN / anzahl_presenter
gen  eea_5bus = EEA_5hBUS / anzahl_presenter
gen  eea_5train = EEA_5hTRAIN / anzahl_presenter
gen  ntm_5bus = NTM_RFI2__5hBUS / anzahl_presenter
gen  ntm_5train = NTM_RFI2__5hTRAIN / anzahl_presenter
gen  ntm_5train_green = NTM_RFI2__5hTRAIN_Green_energy / anzahl_presenter

gen  uk_20bus = UK_20hBUS / anzahl_presenter
gen  uk_20train = UK_20hTRAIN / anzahl_presenter
gen  uba_20bus = UBA_20h_BUS / anzahl_presenter
gen  uba_20train = UBA_20hTRAIN / anzahl_presenter
gen  eea_20bus = EEA_20hBUS / anzahl_presenter
gen  eea_20train = EEA_20hTRAIN / anzahl_presenter
gen  ntm_20bus = NTM_RFI2__20hBUS / anzahl_presenter
gen  ntm_20train = NTM_RFI2__20hTRAIN / anzahl_presenter
gen  ntm_20train_green = NTM_RFI2__20hTRAIN_Green_energy / anzahl_presenter

*Draw 2500 random samples of 1656 participants (25% of all participants)
forvalues i= 1/2500 {
generate random = runiform()
sort random
gen sample_`i' = _n <= 1656
drop random
} 


* Averages for each sample
gen uk_5bus_mean = .
forvalues i=1/2500{
sum uk_5bus if sample_`i' ==1
replace uk_5bus_mean = r(mean) if ID == `i'
}

gen uk_5train_mean = .
forvalues i=1/2500{
sum uk_5train if sample_`i' ==1
replace uk_5train_mean = r(mean) if ID == `i'
}

gen uk_20bus_mean = .
forvalues i=1/2500{
sum uk_20bus if sample_`i' ==1
replace uk_20bus_mean = r(mean) if ID == `i'
}

gen uk_20train_mean = .
forvalues i=1/2500{
sum uk_20train if sample_`i' ==1
replace uk_20train_mean = r(mean) if ID == `i'
}


gen uba_5bus_mean = .
forvalues i=1/2500{
sum uba_5bus if sample_`i' ==1
replace uba_5bus_mean = r(mean) if ID == `i'
}

gen uba_5train_mean = .
forvalues i=1/2500{
sum uba_5train if sample_`i' ==1
replace uba_5train_mean = r(mean) if ID == `i'
}

gen uba_20bus_mean = .
forvalues i=1/2500{
sum uba_20bus if sample_`i' ==1
replace uba_20bus_mean = r(mean) if ID == `i'
}

gen uba_20train_mean = .
forvalues i=1/2500{
sum uba_20train if sample_`i' ==1
replace uba_20train_mean = r(mean) if ID == `i'
}


gen eea_5bus_mean = .
forvalues i=1/2500{
sum eea_5bus if sample_`i' ==1
replace eea_5bus_mean = r(mean) if ID == `i'
}

gen eea_5train_mean = .
forvalues i=1/2500{
sum eea_5train if sample_`i' ==1
replace eea_5train_mean = r(mean) if ID == `i'
}

gen eea_20bus_mean = .
forvalues i=1/2500{
sum eea_20bus if sample_`i' ==1
replace eea_20bus_mean = r(mean) if ID == `i'
}

gen eea_20train_mean = .
forvalues i=1/2500{
sum eea_20train if sample_`i' ==1
replace eea_20train_mean = r(mean) if ID == `i'
}


gen ntm_5bus_mean = .
forvalues i=1/2500{
sum ntm_5bus if sample_`i' ==1
replace ntm_5bus_mean = r(mean) if ID == `i'
}

gen ntm_5train_mean = .
forvalues i=1/2500{
sum ntm_5train if sample_`i' ==1
replace ntm_5train_mean = r(mean) if ID == `i'
}

gen ntm_5train_green_mean = .
forvalues i=1/2500{
sum ntm_5train_green if sample_`i' ==1
replace ntm_5train_green_mean = r(mean) if ID == `i'
}

gen ntm_20bus_mean = .
forvalues i=1/2500{
sum ntm_20bus if sample_`i' ==1
replace ntm_20bus_mean = r(mean) if ID == `i'
}

gen ntm_20train_mean = .
forvalues i=1/2500{
sum ntm_20train if sample_`i' ==1
replace ntm_20train_mean = r(mean) if ID == `i'
}

gen ntm_20train_green_mean = .
forvalues i=1/2500{
sum ntm_20train_green if sample_`i' ==1
replace ntm_20train_green_mean = r(mean) if ID == `i'
}

sort ID

* Variable 
input str50 estimation
"uk_5bus"
"uk_5train"
"uk_20bus"
"uk_20train"
"uba_5bus"
"uba_5train"
"uba_20bus"
"uba_20train"
"eea_5bus"
"eea_5train"
"eea_20bus"
"eea_20train"
"ntm_5bus"
"ntm_5train"
"ntm_5train_green"
"ntm_20bus"
"ntm_20train"
"ntm_20train_green"
end

* Generate table with means and sd of the averages
gen online25_mittelwert = .
gen online25_std = .

sum uk_5bus_mean
replace online25_mittelwert = r(mean) if ID == 1
replace online25_std = r(sd) if ID == 1

sum uk_5train_mean
replace online25_mittelwert = r(mean) if ID == 2
replace online25_std = r(sd) if ID == 2

sum uk_20bus_mean
replace online25_mittelwert = r(mean) if ID == 3
replace online25_std = r(sd) if ID == 3

sum uk_20train_mean
replace online25_mittelwert = r(mean) if ID == 4
replace online25_std = r(sd) if ID == 4

sum uba_5bus_mean
replace online25_mittelwert = r(mean) if ID == 5
replace online25_std = r(sd) if ID == 5

sum uba_5train_mean
replace online25_mittelwert = r(mean) if ID == 6
replace online25_std = r(sd) if ID == 6

sum uba_20bus_mean
replace online25_mittelwert = r(mean) if ID == 7
replace online25_std = r(sd) if ID == 7

sum uba_20train_mean
replace online25_mittelwert = r(mean) if ID == 8
replace online25_std = r(sd) if ID == 8

sum eea_5bus_mean
replace online25_mittelwert = r(mean) if ID == 9
replace online25_std = r(sd) if ID == 9

sum eea_5train_mean
replace online25_mittelwert = r(mean) if ID == 10
replace online25_std = r(sd) if ID == 10

sum eea_20bus_mean
replace online25_mittelwert = r(mean) if ID == 11
replace online25_std = r(sd) if ID == 11

sum eea_20train_mean
replace online25_mittelwert = r(mean) if ID == 12
replace online25_std = r(sd) if ID == 12

sum ntm_5bus_mean
replace online25_mittelwert = r(mean) if ID == 13
replace online25_std = r(sd) if ID == 13

sum ntm_5train_mean
replace online25_mittelwert = r(mean) if ID == 14
replace online25_std = r(sd) if ID == 14

sum ntm_5train_green_mean
replace online25_mittelwert = r(mean) if ID == 15
replace online25_std = r(sd) if ID == 15

sum ntm_20bus_mean
replace online25_mittelwert = r(mean) if ID == 16
replace online25_std = r(sd) if ID == 16

sum ntm_20train_mean
replace online25_mittelwert = r(mean) if ID == 17
replace online25_std = r(sd) if ID == 17

sum ntm_20train_green_mean
replace online25_mittelwert = r(mean) if ID == 18
replace online25_std = r(sd) if ID == 18

keep estimation online25_*
save "online25.dta", replace


******************************************************
**			10% online, randomly chosen 			**
******************************************************

clear all
import excel "SimulationHybrid.xlsx", sheet("Tabelle1") firstrow

expand(anzahl_presenter)

keep if Year ==2020

*generate ID
gen ID = _n

gen  uk_5bus = UK_5hBUS / anzahl_presenter
gen  uk_5train = UK_5hTRAIN / anzahl_presenter
gen  uba_5bus = UBA_5hBUS / anzahl_presenter
gen  uba_5train = UBA_5hTRAIN / anzahl_presenter
gen  eea_5bus = EEA_5hBUS / anzahl_presenter
gen  eea_5train = EEA_5hTRAIN / anzahl_presenter
gen  ntm_5bus = NTM_RFI2__5hBUS / anzahl_presenter
gen  ntm_5train = NTM_RFI2__5hTRAIN / anzahl_presenter
gen  ntm_5train_green = NTM_RFI2__5hTRAIN_Green_energy / anzahl_presenter

gen  uk_20bus = UK_20hBUS / anzahl_presenter
gen  uk_20train = UK_20hTRAIN / anzahl_presenter
gen  uba_20bus = UBA_20h_BUS / anzahl_presenter
gen  uba_20train = UBA_20hTRAIN / anzahl_presenter
gen  eea_20bus = EEA_20hBUS / anzahl_presenter
gen  eea_20train = EEA_20hTRAIN / anzahl_presenter
gen  ntm_20bus = NTM_RFI2__20hBUS / anzahl_presenter
gen  ntm_20train = NTM_RFI2__20hTRAIN / anzahl_presenter
gen  ntm_20train_green = NTM_RFI2__20hTRAIN_Green_energy / anzahl_presenter

*Draw 2500 random samples of 1987 participants (10% of all participants)
forvalues i= 1/2500 {
generate random = runiform()
sort random
gen sample_`i' = _n <= 1987
drop random
} 


* Averages for each sample
gen uk_5bus_mean = .
forvalues i=1/2500{
sum uk_5bus if sample_`i' ==1
replace uk_5bus_mean = r(mean) if ID == `i'
}

gen uk_5train_mean = .
forvalues i=1/2500{
sum uk_5train if sample_`i' ==1
replace uk_5train_mean = r(mean) if ID == `i'
}

gen uk_20bus_mean = .
forvalues i=1/2500{
sum uk_20bus if sample_`i' ==1
replace uk_20bus_mean = r(mean) if ID == `i'
}

gen uk_20train_mean = .
forvalues i=1/2500{
sum uk_20train if sample_`i' ==1
replace uk_20train_mean = r(mean) if ID == `i'
}


gen uba_5bus_mean = .
forvalues i=1/2500{
sum uba_5bus if sample_`i' ==1
replace uba_5bus_mean = r(mean) if ID == `i'
}

gen uba_5train_mean = .
forvalues i=1/2500{
sum uba_5train if sample_`i' ==1
replace uba_5train_mean = r(mean) if ID == `i'
}

gen uba_20bus_mean = .
forvalues i=1/2500{
sum uba_20bus if sample_`i' ==1
replace uba_20bus_mean = r(mean) if ID == `i'
}

gen uba_20train_mean = .
forvalues i=1/2500{
sum uba_20train if sample_`i' ==1
replace uba_20train_mean = r(mean) if ID == `i'
}


gen eea_5bus_mean = .
forvalues i=1/2500{
sum eea_5bus if sample_`i' ==1
replace eea_5bus_mean = r(mean) if ID == `i'
}

gen eea_5train_mean = .
forvalues i=1/2500{
sum eea_5train if sample_`i' ==1
replace eea_5train_mean = r(mean) if ID == `i'
}

gen eea_20bus_mean = .
forvalues i=1/2500{
sum eea_20bus if sample_`i' ==1
replace eea_20bus_mean = r(mean) if ID == `i'
}

gen eea_20train_mean = .
forvalues i=1/2500{
sum eea_20train if sample_`i' ==1
replace eea_20train_mean = r(mean) if ID == `i'
}


gen ntm_5bus_mean = .
forvalues i=1/2500{
sum ntm_5bus if sample_`i' ==1
replace ntm_5bus_mean = r(mean) if ID == `i'
}

gen ntm_5train_mean = .
forvalues i=1/2500{
sum ntm_5train if sample_`i' ==1
replace ntm_5train_mean = r(mean) if ID == `i'
}

gen ntm_5train_green_mean = .
forvalues i=1/2500{
sum ntm_5train_green if sample_`i' ==1
replace ntm_5train_green_mean = r(mean) if ID == `i'
}

gen ntm_20bus_mean = .
forvalues i=1/2500{
sum ntm_20bus if sample_`i' ==1
replace ntm_20bus_mean = r(mean) if ID == `i'
}

gen ntm_20train_mean = .
forvalues i=1/2500{
sum ntm_20train if sample_`i' ==1
replace ntm_20train_mean = r(mean) if ID == `i'
}

gen ntm_20train_green_mean = .
forvalues i=1/2500{
sum ntm_20train_green if sample_`i' ==1
replace ntm_20train_green_mean = r(mean) if ID == `i'
}

sort ID

* Variable 
input str50 estimation
"uk_5bus"
"uk_5train"
"uk_20bus"
"uk_20train"
"uba_5bus"
"uba_5train"
"uba_20bus"
"uba_20train"
"eea_5bus"
"eea_5train"
"eea_20bus"
"eea_20train"
"ntm_5bus"
"ntm_5train"
"ntm_5train_green"
"ntm_20bus"
"ntm_20train"
"ntm_20train_green"
end

* Generate table with means and sd of the averages
gen online10_mittelwert = .
gen online10_std = .

sum uk_5bus_mean
replace online10_mittelwert = r(mean) if ID == 1
replace online10_std = r(sd) if ID == 1

sum uk_5train_mean
replace online10_mittelwert = r(mean) if ID == 2
replace online10_std = r(sd) if ID == 2

sum uk_20bus_mean
replace online10_mittelwert = r(mean) if ID == 3
replace online10_std = r(sd) if ID == 3

sum uk_20train_mean
replace online10_mittelwert = r(mean) if ID == 4
replace online10_std = r(sd) if ID == 4

sum uba_5bus_mean
replace online10_mittelwert = r(mean) if ID == 5
replace online10_std = r(sd) if ID == 5

sum uba_5train_mean
replace online10_mittelwert = r(mean) if ID == 6
replace online10_std = r(sd) if ID == 6

sum uba_20bus_mean
replace online10_mittelwert = r(mean) if ID == 7
replace online10_std = r(sd) if ID == 7

sum uba_20train_mean
replace online10_mittelwert = r(mean) if ID == 8
replace online10_std = r(sd) if ID == 8

sum eea_5bus_mean
replace online10_mittelwert = r(mean) if ID == 9
replace online10_std = r(sd) if ID == 9

sum eea_5train_mean
replace online10_mittelwert = r(mean) if ID == 10
replace online10_std = r(sd) if ID == 10

sum eea_20bus_mean
replace online10_mittelwert = r(mean) if ID == 11
replace online10_std = r(sd) if ID == 11

sum eea_20train_mean
replace online10_mittelwert = r(mean) if ID == 12
replace online10_std = r(sd) if ID == 12

sum ntm_5bus_mean
replace online10_mittelwert = r(mean) if ID == 13
replace online10_std = r(sd) if ID == 13

sum ntm_5train_mean
replace online10_mittelwert = r(mean) if ID == 14
replace online10_std = r(sd) if ID == 14

sum ntm_5train_green_mean
replace online10_mittelwert = r(mean) if ID == 15
replace online10_std = r(sd) if ID == 15

sum ntm_20bus_mean
replace online10_mittelwert = r(mean) if ID == 16
replace online10_std = r(sd) if ID == 16

sum ntm_20train_mean
replace online10_mittelwert = r(mean) if ID == 17
replace online10_std = r(sd) if ID == 17

sum ntm_20train_green_mean
replace online10_mittelwert = r(mean) if ID == 18
replace online10_std = r(sd) if ID == 18

keep estimation online10_*
save "online10.dta", replace


